package zhaoq_hero.webviewshow;

import android.graphics.Bitmap;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

/**
 * ProjectName : zhaoq_hero.webviewshow
 * Created by : zhaoQiang
 * Email : zhaoq_hero163.com
 * On 2015/10/30
 * 16 / 53
 */

/**
 * 用于处理  webView加载时的进度   标题等的信息
 */
public class MyWebViewChromeClient extends WebChromeClient{


    private BrowserSupport browserSupport;

    public MyWebViewChromeClient(BrowserSupport browserSupport) {
        this.browserSupport = browserSupport;
    }

    /**
     * 接受图片并修改图片内容：  设置logo
     * @param view
     * @param icon
     */
    @Override
    public void onReceivedIcon(WebView view, Bitmap icon) {


        if (browserSupport!=null){
            browserSupport.onReceivedIcon(icon);
        }

        super.onReceivedIcon(view, icon);
    }

    /**
     * 回调   进度改变的方法：
     * @param view
     * @param newProgress
     */
    @Override
    public void onProgressChanged(WebView view, int newProgress) {

        if (browserSupport !=null)
        {
            browserSupport.onProgressUpdate(newProgress);
        }
        super.onProgressChanged(view, newProgress);
    }

    /**
     * 当网页加载完成  解析初标题字段的时候  会回调这个方法  并设置标题
     * @param view
     * @param title
     */
    @Override
    public void onReceivedTitle(WebView view, String title) {

        if (browserSupport!=null){

            browserSupport.onReceivedTitle(title);

        }

        super.onReceivedTitle(view, title);

    }
}
